package com.sisSaude.collections;

import java.util.Vector;

import javax.faces.model.SelectItem;

import com.sisSaude.entityBeans.GenericEntityBean;

public class GenericCollection<T extends GenericEntityBean> {

	// fields
	private Vector<T> itens = new Vector<T>();
	private Vector<SelectItem> selectedItens = null;

	// public methods
	public T find(int id) {
		for (T e : itens) {
			if (e.getId() == id)
				return e;
		}
		return null;
	}
	
	// getters
	public Vector<T> getItens() {
		return itens;
	}	
	public Vector<SelectItem> getSelectedItens() {
		if (selectedItens == null) {
			selectedItens = new Vector<SelectItem>();
			selectedItens.add(new SelectItem("0", "-- selecione --"));
			for (T e : itens)
				selectedItens.add(new SelectItem(e.getId(), e.getCaption()));
		}
		return selectedItens;
	}
	
}